package com.iiiss.template.ssh.impl.daos;

import java.util.Date;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.iiiss.template.ssh.common.impl.BaseDao;
import com.iiiss.template.ssh.core.beans.IExampleEvent;
import com.iiiss.template.ssh.core.daos.IExampleEventDao;

/*
 * TemplateSSH - com.iiiss.template.ssh.impl.daos - EventDao.java
 * 
 * Copyright (C) 2011  Mingye Cheng <Cheng, Mingye at GMAIL>
 * 
 * EventDao.java is part of <iiiStudio Template Framework> project.
 * This project is hosted at <http://iiiss-template-ssh.googlecode.com>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Revision history:
 * [2011-5-30] Mingye Cheng - Initial version established.
 * [2011-9-2] Mingye Cheng - Interfaces of 'IPersistenceManager' changed.
 * [2011-10-21] Mingye Cheng - Renamed to 'ExampleEventDao'.
 */
@Transactional
public class ExampleEventDao extends BaseDao implements IExampleEventDao {
	public static final String BEAN_NAME = "event";

	public IExampleEvent createEvent(String title) {
		IExampleEvent event = persistenceManager.newObject(BEAN_NAME);
		event.setTime(new Date());
		event.setTitle(title);
		return event;
	}

	public IExampleEvent getEventById(long id) {
		return persistenceManager.getObject(BEAN_NAME, id);
	}

	public IExampleEvent getEventByTitle(String title) {
		return persistenceManager
				.getObject(BEAN_NAME, "where title = ?", title);
	}

	public List<IExampleEvent> getAllEvents() {
		return persistenceManager.getObjects(BEAN_NAME, null, null);
	}

	public void removeEvent(IExampleEvent event) {
		persistenceManager.deteleObject(event);
	}
}
